package com.five.novel.mapper;


import com.five.basic.mapper.BaseMapper;
import com.five.pojo.Novel;
import com.five.vo.NovelRankVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NovelMapper extends BaseMapper<Novel> {

    /**
     * 收藏榜 Top10
     */
    @Select("SELECT id, title, cover, author_id, category_id, " +
            "score, word_count, collect_count, status " +
            "FROM t_novel " +
            "WHERE status IN (1,2) " +
            "ORDER BY collect_count DESC " +
            "LIMIT 10")
    @Results({
            @Result(column = "author_id", property = "authorId"),
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "word_count", property = "wordCount"),
            @Result(column = "collect_count", property = "collectCount")
    })
    List<NovelRankVo> selectTop10ByCollect();

    /**
     * 根据分类查询已上架小说，按收藏量倒序
     */
    @Select("SELECT id, title, cover, score, word_count, collect_count, status " +
            "FROM t_novel " +
            "WHERE category_id = #{categoryId} " +
            "  AND status IN (1, 2) " +
            "ORDER BY collect_count DESC")
    @Results({
            @Result(column = "word_count", property = "wordCount"),
            @Result(column = "collect_count", property = "collectCount")
    })
    List<NovelRankVo> selectByCategoryId(@Param("categoryId") Long categoryId);
}